<?php

class base_test
{
	
	/**
	 * @var db
	 */
	protected $db;
	
	/**
	 * @var test_results
	 */
	protected $test_results;
	
	public function __construct()
	{
		global $db;
		$this->db = $db;
		
		global $test_results;
		$this->test_results = $test_results;
	}
	
	public function set_up()
	{
		
	}
	
	public function tear_down()
	{
		
	}

	protected function assert_true($real_value)
	{
		if ($real_value !== true)
		{
			$real_value = var_export($real_value, true);
			$this->test_results->add_error("The value is not true: {$real_value}");
		}
	}

	protected function assert_false($real_value)
	{
		if ($real_value !== false)
		{
			$real_value = var_export($real_value, true);
			$this->test_results->add_error("The value is not false: {$real_value}");
		}
	}

	protected function assert_equal($real_value, $correct_value)
	{
		if ($real_value != $correct_value)
		{
			$real_value = var_export($real_value, true);
			$correct_value = var_export($correct_value, true);
			$this->test_results->add_error("Values are not equal: {$real_value} vs. {$correct_value}");
		}
	}

	protected function assert_identical($real_value, $correct_value)
	{
		if ($real_value !== $correct_value)
		{
			//$real_value_type = gettype($real_value);
			//$correct_value_type = gettype($correct_value);
			$real_value = var_export($real_value, true);
			$correct_value = var_export($correct_value, true);
			//$this->test_results->add_error("Values are not identical: {$real_value_type}[{$real_value}] vs. {$correct_value_type}[{$correct_value}]");
			$this->test_results->add_error("Values are not identical: {$real_value} vs. {$correct_value}");
		}
	}
	
	protected function assert_db_value($table_name, $column_name, $id, $correct_value)
	{
		$real_value = $this->db->get_value("SELECT `{$column_name}` FROM `{$table_name}` WHERE id = {$id}");
		if ($real_value != $correct_value)
		{
			$this->test_results->add_error("DB: Real value <> Correct value: [{$real_value}] vs. [{$correct_value}]");
		}
	}
	
	protected function assert_db_row_exists($sql)
	{
		if (!$this->db->row_exists($sql))
		{
			$this->test_results->add_error("DB: Row does not exist: [{$sql}]");
		}
	}
	
}

?>